<?php
/**
 * Created by PhpStorm.
 * User: peter
 * Date: 18-9-27
 * Time: 上午10:41
 */

namespace app\club\controller;


use think\Request;

class Activity extends Auth
{
    /**
     * @purpose 批量设置上车点人数限制
     * @param Request $request
     * @return array
     * @throws \Exception
     */
    public function batchSetCollectionPointNumberOfPeople (Request $request)
    {
        $data       = $request->post();
        return \app\club\logic\Activity::batchSetCollectionPointNumberOfPeople($data);
    }
    /**
     * @purpose 添加集合点
     * @param Request $request
     * @return array
     */
    public function createCollectionPoint (Request $request)
    {
        $data   = $request->post();
        return \app\club\logic\Activity::createCollectionPoint($data);
    }
    /**
     * @purpose 编辑集合点
     * @param Request $request
     * @return array
     */
    public function editCollectionPoint (Request $request)
    {
        $data       = $request->post();
        return \app\club\logic\Activity::editCollectionPoint($data);
    }
    /**
     * @purpose 获取团期集合点列表
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function collectionPointItems (Request $request) {
        $group_stage_id     = $request->get('group_stage_id', 0);
        return \app\club\logic\Activity::collectionPointItems($group_stage_id);
    }
    /**
     * @purpose 发布活动
     * @param Request $request
     * @return array
     * @throws \think\exception\PDOException
     */
    public function add (Request $request)
    {
        $data = $request->post();
        return \app\club\logic\Activity::add($data,self::$uid);
    }

    /**
     * @purpose 通过俱乐部ID获取活动列表(可通过区域选择显示活动)
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function activityItems (Request $request)
    {
        $page       = $request->get('page', 1);
        $size       = $request->get('size', 20);
        $kw         = $request->get('kw', '');
        $status     = $request->get('status', '');
        $where = [];
        $where[] = ['a.club_id', '=', self::$uid];
        if ((int) $status === 1) {
            $where[] = ['gs.status', '=', 1];
        }
        if ($kw) {
            $where[] = ['a.title', ['like', $kw.'%'], ['like', '%'.$kw.'%'], ['like', '%'.$kw], 'or'];
        }
        if ((int) $status === 99) {
            $where[] = ['gs.status', '=', 99];
            $where[] = ['gs.start_time', '>', time()];
        }
        if ((int) $status === 0) {
            $where[] = ['gs.end_time', '<', time() - (3600 * 24)];
        }
        if ($status === 'traveling') {
            $where[] = ['gs.start_time', '<', time()];
            $where[] = ['gs.end_time', '>', time() - (3600 * 24)];
        }
        return \app\club\logic\Activity::activityItems(
            $where,
            $page,
            $size
        );
    }

    /**
     * @purpose 获取单条活动数据(用于修改本条活动信息)
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function activitySingleData (Request $request)
    {
        $id = $request->get('activity_id',-1);
        return \app\club\logic\Activity::activitySingleData($id);
    }

    /**
     * @purpose 通过活动ID修改活动信息
     * @param Request $request
     * @return array
     */
    public function activityEdit (Request $request)
    {
        $data  =  $request->post();
        return \app\club\logic\Activity::activityEdit($data);
    }

    /**
     * @purpose 更改活动状态
     * @param Request $request
     * @return array
     */
    public function editUpperAndLower (Request $request)
    {
        $data = $request->post();
        return \app\club\logic\Activity::editUpperAndLower($data);
    }

    /**
     * @purpose 获取单条团期数据
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function groupStageSingleData (Request $request)
    {
        $id = $request->get('group_stage_id',-1);
        return \app\club\logic\Activity::groupStageSingleData($id);
    }

    /**
     * @purpose 通过团期ID修改团期信息
     * @param Request $request
     * @return array
     */
    public function groupStageEdit (Request $request)
    {
        $data  =  $request->post();
        return \app\club\logic\Activity::groupStageEdit($data);
    }


    /**
     * aa
     * @purpose 通过活动ID获取团期列表
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function groupItems (Request $request)
    {
        $activity_id = $request->get('activity_id') ? $request->get('activity_id') : null;
        $page        = $request->get('page',1);
        $size        = $request->get('size',50);
        return \app\club\logic\Activity::groupItems($activity_id,$page,$size);
    }

    /**
     * @purpose 通过团期ID获取集合点列表
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function collectionItems(Request $request)
    {
        $activity_group_stage_id =
            $request->get('activity_group_stage_id') ?
                $request->get('activity_group_stage_id') : null;
        $page                    = $request->get('page',1);
        $size                    = $request->get('size',50);
        return \app\club\logic\Activity::collectionItems($activity_group_stage_id,$page,$size);
    }



    /**
     * @purpose 通过上车集合点ID修改上车集合点
     * @param Request $request
     * @return array
     */
    public function collectionPointEdit (Request $request)
    {
        $data  =  $request->post();
        return \app\club\logic\Activity::collectionPointEdit($data);
    }

    /**
     * @purpose 删除活动(软删除)
     * @param Request $request
     * @return array
     * @throws \Exception
     */
    public function activityDelete (Request $request)
    {
        $id  =  $request->post('id');
        return \app\club\logic\Activity::activityDelete($id);
    }

    /**
     * @purpose 删除团期(软删除)
     * @param Request $request
     * @return array
     */
    public function groupStageDelete (Request $request)
    {
        $id  =  $request->post('id');
        return \app\club\logic\Activity::groupStageDelete($id);
    }

    /**
     * @purpose 删除上车集合点(软删除)
     * @param Request $request
     * @return mixed
     */
    public function collectionPointDelete (Request $request)
    {
        $id  =  $request->post('id');
        return \app\club\logic\Activity::collectionPointDelete($id);
    }
}